<?php

// Error if we don't have a Project ID and Crudset ID
//Incluce DB connect 
include_once "quickcrud_connect.php";
//include_once "commonctls.php";
include "CF_mysql_com.php";
include_once "CF_all_com.php";
include_once "qc_functions.php";

if (!isset($_REQUEST['project_id']) ){
	print 'Please select or create a project first';
exit;
}

$project_id = $_REQUEST['project_id'];

if (!isset($_REQUEST['table']) ){



    $current_db = lookup_value('project_db', 'projects', "project_id = $project_id");
    $ar_tables = get_array_query("show tables in $current_db");
    $col_name = 'Tables_in_' . $current_db;
    $dd_tables =  make_array_dd($ar_tables, 'table', $col_name, $col_name, 0);

    $txt_select_table = "<form name='select_table' action='get_table_vars.php' method='get'>\n";
    $txt_select_table .= "<p>Select Table Name</p>\n <p>$dd_tables</p>\n";
    $txt_select_table .= "<input type='hidden' name='project_id' value='$project_id' ><input type='submit' value='go'>\n";
    echo $txt_select_table;

	exit;
}


if (!isset($_REQUEST['alias'])){
	$alias =  $_REQUEST['table'];
}

if (!isset($_REQUEST['condition'])){
	$condition = '1';
}


$table = $_REQUEST['table'];
$project_id = $_REQUEST['project_id'];
$fieldspec = get_table_vars($table, $project_id);



if($_REQUEST['output'] == 'screen')	{
	echo "<html>\n<head>\n</head>\n<body>";
	echo "<TEXTAREA NAME=\"comments\" COLS='80' ROWS='20'>$fieldspec</TEXTAREA>\n";
	echo "</body></html>";
} else{
	$result = urlencode($result);

	$header_text = "Location: leftmenu.php?project_id=$project_id&crudset_id=$crudset_id&result=$result";
	header($header_text); /* Redirect browser */
	exit;
}


?>